﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Utils;
namespace UI.ModEmployee
{
    public partial class EmpReInList : System.Web.UI.Page
    {
        EmpReInBiz empReInBiz = new EmpReInBiz();
        string empCode = "";
        string account = "";
        protected void Page_Init(object sender, EventArgs e)
        {
            if (Session["user"] != null)
            {
                User user = Session["user"] as User;
                account = user.Account;
            }
            else
            {
                JSUtility.Alert(this, "您没有登录!请先登录。");
                return;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Params["EmpCode"] != null) empCode = Request.Params["EmpCode"].ToString().Trim();
        
            if (!IsPostBack)
            {

                btnAdd.Attributes.Add("onclick", "javascript:ShowLink('EmpReInAdd.aspx',800,550);");
            
                    new DepartmentBiz().InitDropDownList(ddlDeptID, "0");//针对一层结构使用
             
                if (empCode != "")
                {
                    txtSerWord.Text = empCode;
                    string bTm = System.DateTime.Now.AddMonths(-2).ToString("yyyy-MM-dd");
                    txtBtime.Text = bTm;
                    txtEtime.Text = System.DateTime.Now.ToString("yyyy-MM-dd");
                    BondGvList(empCode, bTm, System.DateTime.Now.ToString("yyyy-MM-dd"), "返聘", "0");
                }
               
            }
        }
        protected void BondGvList(string serWord, string bTime, string eTime, string changeTypeName, string deptID)
        {
            DataTable dt = empReInBiz.GetLists(serWord, bTime, eTime, changeTypeName, deptID);

            if (dt.Rows.Count > 0)
            {
                lbAmount.Text = "人数合计:    " + dt.Rows.Count;
            }
            else
            {
                lbAmount.Text = "";
            }
            //DataRow dr = dt.NewRow();
            //dr[9] = "合计:";
            //dr[10] = dt.Rows.Count;
            //dt.Rows.Add(dr);
            gvList.DataSource = dt;
            gvList.DataBind();

        }

        protected void btnEmSearch_Click(object sender, EventArgs e)
        {
            if (!AccountBiz.CheckRight(account, "EmpReInList.aspx", RightChar.Ser))
            {
                JSUtility.Alert(this, "您没有查询权限！");
                return;
            }
            string serWord = txtSerWord.Text.Trim();
            string bTime = txtBtime.Text.Trim();
            string eTime = txtEtime.Text.Trim();
            string changeTypeName = ddlReInTypeName.SelectedItem.Text.Trim();
            if (ddlReInTypeName.SelectedValue == "0") changeTypeName = "";
            string deptID = ddlDeptID.SelectedValue.ToString();


            if (serWord == "" && bTime == "" && eTime == "" && deptID == "0")
            {
                bTime = System.DateTime.Now.AddMonths(-2).ToString("yyyy-MM-dd");
                eTime = System.DateTime.Now.ToString("yyyy-MM-dd");
            }
            if (StringUtility.GetDiffDays(bTime, eTime) > XmlUtility.GetNumFormConfig("daysOfSearch"))
            {
                JSUtility.Alert(this, "查询日期间隔不能大于" + XmlUtility.GetNumFormConfig("daysOfSearch") + "天！");
                return;
            }

            BondGvList(serWord, bTime, eTime, changeTypeName, deptID);
        }

       

        protected void gvList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)
            {
                e.Row.Cells[0].Visible = false;
            }
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#F3F8F8'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
                HyperLink hlCode = (HyperLink)e.Row.Cells[1].FindControl("hlEmpCode");
                HyperLink hlName = (HyperLink)e.Row.Cells[1].FindControl("hlEmpName");
                string urlParam = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "ReInID"));
                hlCode.NavigateUrl = "javascript:ShowLink('EmpReInAdd.aspx?ReInID=" + urlParam + "',800,550)";
                hlName.NavigateUrl = "javascript:ShowLink('EmpReInAdd.aspx?ReInID=" + urlParam + "',800,550)";
            }
        }






    }
}